package leecode

func subarraySum(nums []int, k int) (result int) {
	//求出数组的前缀和
	prefixSum := make([]int, len(nums)+1)
	for i := 0; i < len(nums); i++ {
		prefixSum[i+1] = prefixSum[i] + nums[i]
	}
	//遍历前缀和数组
	for i := 0; i < len(prefixSum); i++ {
		for j := i + 1; j < len(prefixSum); j++ {
			if prefixSum[j]-prefixSum[i] == k {
				result++
			}
		}
	}
	return
}
